import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
import Index from '../views/index.vue'

Vue.use(VueRouter)

const routes = [{
	path: '/',
	name: 'Home',
	component: Index,
	meta: {
		keepAlive: true
	}
},
{
	path: '/fruit',
	name: 'Fruit',
	component: (resolve) => {
		require(['../views/Fruit.vue'], resolve)
	},
	meta: {
		keepAlive: true
	},
	children: [

	]
},
{
	path: '/shopPage',
	name: 'ShopPage',
	component: (resolve) => {
		require(['../views/shopPage.vue'], resolve)
	},
	meta: {
		keepAlive: true
	},
	children: [

	]
},
{
	path: '/morelist',
	name: 'MoreList',
	component: (resolve) => {
		require(['../views/MoreList.vue'], resolve)
	},
	children: [

	]
},
{
	path: '/integral',
	name: 'Integral',
	component: (resolve) => {
		require(['../views/Integral/index.vue'], resolve)
	}
},
{
	path: '/fruit/detail',
	name: 'Fruit/Detail',
	component: (resolve) => {
		require(['../views/Fruit/detail.vue'], resolve)
	}
},
{
	path: '/fruit/detail_2',
	name: 'Fruit/Detail2',
	component: (resolve) => {
		require(['../views/Fruit/detail_2.vue'], resolve)
	}
},
{
	path: '/seafood',
	name: 'SeaFood',
	component: (resolve) => {
		require(['../views/SeaFood.vue'], resolve)
	}
},
{
	path: '/meat',
	name: 'Meat',
	component: (resolve) => {
		require(['../views/Meat.vue'], resolve)
	}
},
{
	path: '/flavor',
	name: 'Flavor',
	component: (resolve) => {
		require(['../views/Flavor.vue'], resolve)
	}
},
{
	path: '/snacks',
	name: 'Snacks',
	component: (resolve) => {
		require(['../views/Snacks.vue'], resolve)
	}
},

//购物车
{
	path: '/cart',
	component: (resolve) => {
		require(['../views/ShoppingCar/index.vue'], resolve)
	}
},
{
	path: '/confirm_order',
	name: 'confirm_order',
	component: (resolve) => {
		require(['../views/ShoppingCar/confirm_order.vue'], resolve)
	},
	children: [

	]
},
{
	path: '/activityList',
	name: 'ActivityList',
	component: (resolve) => {
		require(['../views/activity/activityList.vue'], resolve)
	}
},
{
	path: '/payType',
	component: (resolve) => {
		require(['../views/ShoppingCar/payType.vue'], resolve)
	}
},
{
	path: '/person',
	name: 'Person',
	component: (resolve) => {
		require(['../views/Person/Person.vue'], resolve)
	},
	children: [{
		path: '/',
		name: 'Message',
		component: (resolve) => {
			require(['../views/Person/index.vue'], resolve)
		}
	},
	{
		path: 'message',
		name: 'Message',
		component: (resolve) => {
			require(['../views/Message/Message.vue'], resolve)
		}
	},

	{
		path: 'exchange',
		name: 'exchange',
		component: (resolve) => {
			require(['../views/Order/exchange.vue'], resolve)
		}
	},
	{
		path: 'de-exchange',
		name: 'de-exchange',
		component: (resolve) => {
			require(['../views/Order/DeExchange.vue'], resolve)
		}
	},
	{
		path: 'returnList',
		name: 'returnList',
		component: (resolve) => {
			require(['../views/Order/returnList.vue'], resolve)
		}
	},
	{
		path: 'storeConfirm',
		name: 'storeConfirm',
		component: (resolve) => {
			require(['../views/Order/storeConfirm.vue'], resolve)
		}
	},
	{
		path: 'focus',
		component: (resolve) => {
			require(['../views/Focus/Collect.vue'], resolve)
		}
	},
	{
		path: 'collect',
		component: (resolve) => {
			require(['../views/Focus/Collect.vue'], resolve)
		}
	},
	{
		path: 'track',
		component: (resolve) => {
			require(['../views/Focus/Track.vue'], resolve)
		}
	},
	{
		path: 'assets',
		component: (resolve) => {
			require(['../views/Assets/Score.vue'], resolve)
		}
	},
	{
		path: 'score',
		component: (resolve) => {
			require(['../views/Assets/Score.vue'], resolve)
		}
	},
	{
		path: 'card',
		component: (resolve) => {
			require(['../views/Assets/Card.vue'], resolve)
		}
	},
	{
		path: 'storecard',
		component: (resolve) => {
			require(['../views/Assets/storecard.vue'], resolve)
		}
	},
	{
		path: 'giftcard',
		component: (resolve) => {
			require(['../views/Assets/Giftcard.vue'], resolve)
		}
	},

	{
		path: 'safecenter',
		component: (resolve) => {
			require(['../views/SafeCenter/index.vue'], resolve)
		}
	},
	{
		path: 'updatephone',
		component: (resolve) => {
			require(['../views/SafeCenter/updatePhone.vue'], resolve)
		}
	},
	{
		path: 'updateemall',
		component: (resolve) => {
			require(['../views/SafeCenter/updateEmall.vue'], resolve)
		}
	},
	{
		path: 'address',
		component: (resolve) => {
			require(['../views/Person/address.vue'], resolve)
		}
	},
	{
		path: 'info',
		component: (resolve) => {
			require(['../views/Person/info.vue'], resolve)
		}
	},
	{
		path: 'order',
		component: (resolve) => {
			require(['../views/Order/index.vue'], resolve)
		}
	},
	{
		path: 'orderdetail',
		component: (resolve) => {
			require(['../views/Order/orderDetail.vue'], resolve)
		}
	},
	{
		path: 'invoice',
		component: (resolve) => {
			require(['../views/Order/Invoice.vue'], resolve)
		}
	},
	{
		path: 'returnlistorderdetail',
		component: (resolve) => {
			require(['../views/Order/returnListOrderDetail.vue'], resolve)
		}
	},
	{
		path: 'checklogistics',
		component: (resolve) => {
			require(['../views/Person/CheckLogistics.vue'], resolve)
		}
	},
	{
		path: 'comment',
		component: (resolve) => {
			require(['../views/Order/comment.vue'], resolve)
		}
	},

	{
		path: 'evaluate',
		component: (resolve) => {
			require(['../views/evaluate/index.vue'], resolve)
		}
	},
	]
},
{
	// 专题列表
	path: '/topic',
	name: 'Topic',
	component: (resolve) => {
		require(['../views/topic.vue'], resolve)
	}
},
{
	//专题详情

	path: '/topicDetail',
	component: (resolve) => {
		require(['../views/topicDetail.vue'], resolve)
	}

},
{
	//top单品

	path: '/top',
	component: (resolve) => {
		require(['../views/top.vue'], resolve)
	}

},
{
	//分类

	path: '/cate',
	component: (resolve) => {
		require(['../views/cate.vue'], resolve)
	},
	meta: {
		keepAlive: true
	}

},
{
	//分类详情

	path: '/cateDetail',
	component: (resolve) => {
		require(['../components/cate/detail.vue'], resolve)
	}

},
{
	//今日优选

	path: '/today',
	component: (resolve) => {
		require(['../views/today.vue'], resolve)
	}

},
{
	//店铺分类

	path: '/shopclass',
	component: (resolve) => {
		require(['../views/shopclass.vue'], resolve)
	}

},
{
	//店铺详情
	path: '/shopindex',
	name: 'ShopIndex',
	component: (resolve) => {
		require(['../views/Shop/shopindex.vue'], resolve)
	}


},
{
	//顶部搜索页面
	path: '/searchpage',
	name: 'SearchPage',
	component: (resolve) => {
		require(['../views/Shop/SearchPage.vue'], resolve)
	}


},
// {
// 	// 店铺秒杀更多
// 	path: '/shopindex/secondsMore',
// 	name: 'SecondsMore',
// 	component: (resolve) => {
// 		require(['../views/Shop/SecondsMore.vue'], resolve)
// 	}


// },
	// {
	// 	//店铺详情
	// 	path: '/shopindextow',
	// 	component: (resolve) => {
	// 		require(['../views/Shop/shopindexTow.vue'], resolve)
	// 	}

	// },
]

const router = new VueRouter({
	// mode: 'history',
	base: process.env.BASE_URL,
	routes,
	scrollBehavior(to, from, savedPosition) {
		console.log(savedPosition)
		if (savedPosition) {
			setTimeout(() => {
				window.scrollTo(savedPosition.x, savedPosition.y)
			}, 500)


			return savedPosition
		} else {
			return {
				x: 0,
				y: 0
			}
		}
	}
})

router.afterEach((to, from, next) => {
	console.log('router.afterEach',to, from, next)
	// console.log('router.afterEach', to, from, next)
	// if(localStorage.getItem("refresh")){
	// 	localStorage.removeItem("refresh")
	// 	to.meta.keepAlive = false
	// }else{
	// 	if(to.name == "ShopIndex"||to.name == "Home"){
	// 		to.meta.keepAlive = true
	// 	}else{
	// 		to.meta.keepAlive = false
	// 	}

	// }
	// window.scrollTo(0, 0)

})
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

export default router
